package com.aurora.source.home.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aurora.source.R;
import com.aurora.source.base.BaseRecyclerAdapter;
import com.aurora.source.base.CommonHolder;
import com.aurora.source.home.bean.BatchManagementBean;

import butterknife.BindView;

public class BatchManagementAdapter extends BaseRecyclerAdapter<BatchManagementBean.BatchListBean> {
    private OnNameClick onNameClick;
    private OnStateClick onStateClick;

    public void setOnNameClick(OnNameClick onNameClick) {
        this.onNameClick = onNameClick;
    }

    public void setOnStateClick(OnStateClick onStateClick) {
        this.onStateClick = onStateClick;
    }

    @Override
    public CommonHolder<BatchManagementBean.BatchListBean> setViewHolder(ViewGroup parent) {
        return new MyHolder(parent.getContext(), parent);
    }

    public interface OnNameClick {
        void onNameClick(BatchManagementBean.BatchListBean data, int position);
    }

    public interface OnStateClick {
        void onStateClick(BatchManagementBean.BatchListBean data, int position);
    }

    class MyHolder extends CommonHolder<BatchManagementBean.BatchListBean> {

        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.tv_confirm)
        TextView tvConfirm;
        @BindView(R.id.ll_name)
        LinearLayout llName;
        @BindView(R.id.iv_edit)
        ImageView ivEdit;

        public MyHolder(Context context, ViewGroup root) {
            super(context, root, R.layout.item_batch_management);
        }

        @Override
        public void bindData(final BatchManagementBean.BatchListBean batchManagementBean, final int positon) {
            tvName.setText(batchManagementBean.getBatchTitle());
            tvTime.setText(batchManagementBean.getCreateTime());
            llName.setOnClickListener(null);
            ivEdit.setVisibility(View.GONE);
            switch (batchManagementBean.getBatchStatus()) {
                case "SUCCESS"://已启用
                    tvConfirm.setTextColor(Color.parseColor("#5DD189"));
                    tvConfirm.setText("启用中");
                    break;
                case "ING"://待启用
                    ivEdit.setVisibility(View.VISIBLE);
                    tvConfirm.setTextColor(Color.parseColor("#222222"));
                    tvConfirm.setText("启用");
                    llName.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (onNameClick != null) {
                                onNameClick.onNameClick(batchManagementBean, positon);
                            }
                        }
                    });
                    break;
                case "ERROR"://停用
                    tvConfirm.setTextColor(Color.parseColor("#888888"));
                    tvConfirm.setText("停用");
                    break;
            }


            tvConfirm.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onStateClick != null) {
                        onStateClick.onStateClick(batchManagementBean, positon);
                    }
                }
            });
        }
    }

}
